package com.lemon.smartsafetynew.ui.adapter.monitor;

import android.graphics.drawable.ColorDrawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.IApplication;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.monitor.MonitorVideoItemVo;

import java.util.List;

import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2017/8/10.
 */

public class MonitorVideoItemAdapter extends LemonRcvAdapter<MonitorVideoItemVo> {

    private RecyclerTClickListener<MonitorVideoItemVo> mListener;

    public MonitorVideoItemAdapter(@Nullable List<MonitorVideoItemVo> data,
                                   RecyclerTClickListener<MonitorVideoItemVo> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new VideoItem();
    }

    private class VideoItem implements AdapterItem<MonitorVideoItemVo> {

        private MonitorVideoItemVo mData;
        private int mPosition;

        private ImageView videoTitleImageView;
        private TextView videoDescription;
        private TextView videoTitleName;
        private LinearLayout videoItemLayout;

        @Override
        public int getLayoutResId() {
            return R.layout.item_video;
        }

        @Override
        public void bindViews(View root) {
            videoTitleImageView = (ImageView) root.findViewById(R.id.video_titleImageView);
            videoDescription = (TextView) root.findViewById(R.id.video_description);
            videoTitleName = (TextView) root.findViewById(R.id.video_titleName);
            videoItemLayout = (LinearLayout) root.findViewById(R.id.video_item_layout);
        }

        @Override
        public void setViews() {
            videoItemLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(mData, mPosition);
                }
            });
        }

        @Override
        public void handleData(MonitorVideoItemVo monitorVideoItemVo, int position) {

            mData = monitorVideoItemVo;
            mPosition = position;

            videoTitleName.setText(Html.fromHtml(monitorVideoItemVo.getTitle()));

            Glide.with(videoTitleImageView.getContext())
                    .load(monitorVideoItemVo.getImageUrl())
                    .placeholder(R.mipmap.icon_video_default_view)
                    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                    .into(videoTitleImageView);

        }
    }
}
